local ST = LibStub("AceAddon-3.0"):GetAddon("SurgeTrack", true)
local STDB = ST:NewModule("SurgeTrack_DB")
local LSM = LibStub("LibSharedMedia-3.0", true)

function ST:LoadSTDB()
 ST:EnableModule("SurgeTrack_DB")
 ST:DisableModule("SurgeTrack_DB")
end
function STDB:OnEnable()
 STDB:LoadMeta()
 STDB:LoadSounds()
 STDB:InitDB()
 STDB:LoadDBData()
end
function STDB:LoadMeta()
 ST.NAME = ST:GetName()
 ST.IMG = "Interface\\Icons\\Ability_Druid_Starfall"
 ST.GATHER = false
 ST.LOCK = true
 ST.ICONTEST = false
end
function STDB:LoadSounds()
 LSM:Register("sound", "SurgeTrack: Glyph_MinorCreate", "Sound\\Interface\\Glyph_MinorCreate.wav")
 LSM:Register("sound", "SurgeTrack: PutDownGems", "Sound\\Interface\\PickUp\\PutDownGems.wav")
 --LSM:List("sound")[index] = "Name"
 --LSM:Fetch("sound", "Name") = "\Path"
end
function STDB:InitDB()
 local defaults = {
  profile = {
   addon = {
    enable = true,
    options = false,
    sound = 1,
   },
   root = {
    scale = 1.5,
    alpha = 1,
    x = nil,
    y = nil,
   },
   flash = {
    enable = false,
    duration = 0.4,
    classcolor = true,
    color = {
     r = 1,
     g = 1,
     b = 1,
     a = 1,
    },
    background = 1,
   },
   unit = {
    amount = 5,
    array = "LEFT",
    centered_align = true,
    gap = 36,
    animation = {
     overlay_glow = true,
     fade_on_expire = false,
     fade_in_out = true,
     silde = false,
    },
   },
   name = {
    enable = true,
    font = 1,
    size = 6,
    position = "BOTTOM",
   },
   stack = {
    enable = true,
    font = 1,
    size = 10,
    one = false,
   },
   cd = {
    enable = true,
    omnicc = false,
   },
   cc = {
    enable = false,
    font = 1,
    size = 8,
   },
   aura = {
    class = ST.data.aura.class,
    common = ST.data.aura.common,
    custom = {},
   },
   spell = {
    class = ST.data.spell.class,
    common = {},
    custom = {},
   },
   style = {
    skinid = "Blizzard",
    gloss = 0,
    backdrop = false,
    colors = {},
   },
   minimap = {
    hide = false,
    minimapPos = 225,
    radius = 80,
   },
  },
 }
 ST.db = LibStub("AceDB-3.0"):New("SurgeTrackDB",defaults)
 
 if type(ST.db.profile.unit.animation) == "boolean" then
  ST.db.profile.unit.animation = {
   overlay_glow = true,
   fade_on_expire = false,
   fade_in_out = true,
   silde = false,
  }
 end
 
end
function STDB:LoadDBData()

 ST.aura = {} --ST.aura[spellId] = need track? true : false

 ST.spell = {} --ST.spell[spellId] = Active-unit index  inActive-false nil-release
 ST.spelldesc = {} --ST.spelldesc[spellName] = spellId

 ST.wait = {} --ST.wait[spellIdStandby] = spellInfoStandby -table   nil-release

 for _, auraTable in pairs(ST.db.profile.aura) do
  for spellId,isEnable in pairs (auraTable) do
  if isEnable then
    ST.aura[spellId] = {track = true,}
   end
  end
 end

 for _, spellTable in pairs(ST.db.profile.spell) do
  for spellId,isEnable in pairs (spellTable) do
  if isEnable then
    ST.spell[spellId] = {track = true,}
    ST.spelldesc[select(1, GetSpellInfo(spellId))] = spellId
   end
  end
 end
end
